﻿using System;
using System.Net;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace BallMadness
{
    public class Enemy
    {
        public Vector2 position;
        TimeSpan timeToHit;
        TimeSpan totalTimeToHit = new TimeSpan(0, 0, 3);
        TimeSpan timeToDisappear;
        TimeSpan totalTimeToDisappear = new TimeSpan(0, 0, 4);

        public Enemy()
        {
            position.X = Worm.randPosition.Next(0, SharedGraphicsDeviceManager.Current.GraphicsDevice.Viewport.Width);
            position.Y = Worm.randPosition.Next(0, SharedGraphicsDeviceManager.Current.GraphicsDevice.Viewport.Height);
            timeToHit = totalTimeToHit;
            timeToDisappear = totalTimeToDisappear;
        }

        public void OnDraw(SpriteBatch spriteBatch)
        {
            Texture2D use = EnemyManager.shadow;
            if (isHit()) use = EnemyManager.paw;

            spriteBatch.Draw(
                use,
                position,
                null,
                Color.White,
                0.0f,
                new Vector2(EnemyManager.shadow.Width / 2, EnemyManager.shadow.Height / 2),
                1.0f,
                SpriteEffects.None,
                1.0f);
        }

        public void OnUpdate(GameTimerEventArgs e)
        {
            timeToDisappear -= e.ElapsedTime;
            timeToHit -= e.ElapsedTime;
        }

        public bool isExpired()
        {
            return timeToDisappear <= TimeSpan.Zero;
        }

        public bool isHit()
        {
            return timeToHit <= TimeSpan.Zero;
        }
    }
}
